library localization_strings;

import 'package:flutter/material.dart';

import '../util.dart';
import 'localization.dart';

class LocalizationStrings {
  // static LocalizationType type = LocalizationType.en;

  static String locaKey = 'localizationKey';

  static Locale get locale {
    switch (type) {
      case LocalizationType.en:
        return const Locale('en');

      default:
        return const Locale('zh');
    }
  }

  static List<LocalizationType> types = [
    LocalizationType.zh,
    LocalizationType.en,
  ];

  static String typeForKey(LocalizationType type) {
    switch (type) {
      case LocalizationType.en:
        return '英语';

      default:
        return '中文';
    }
  }

  static LocalizationType keyForType(String? key) {
    switch (key) {
      case '英语':
      case 'English':
        return LocalizationType.en;
      default:
        return LocalizationType.zh;
    }
  }

  static var typeObs = LocalizationType.en.obs;

  static LocalizationType get type {
    return typeObs.value;
  }

  static set type(LocalizationType val) {
    typeObs.value = val;
    Get.updateLocale(locale);
    SpUtil().setStr(locaKey, typeForKey(val));
  }

  static register() {
    String? ls = SpUtil().getStr(locaKey);
    type = keyForType(ls);
  }
}
